<?php
/*
	Aurus CMS - free OOP CMS
	Copyright (C) 2010  Nestor Yanchuk

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 2 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
if (! defined('ROOT')) die();
if (isset($_POST['login'])) {
	$ar = array(
	'login' => __('Ім\'я'),
	'pass' => __('Пароль'),
	'email' => __('E-mail'),
	'group' => __('Група'),
	);
	if ( count( $nfo = Aurus::getInstance()->checkPostEmpty($ar))) {
		Aurus::getInstance()->addContent( Adminarea::getInstance()->adminInfo(implode('<br />',$nfo)) );
	} else {
		switch (Users::getInstance()->registerUser($_POST['login'],$_POST['pass'],$_POST['email'],'','','','')) {
			case -1:
				$msg = __('Логін містить в собі недозволені символи');
				break;
			case -2:
				$msg = __('Такий користувач вже існує');
				break;
			case -3:
				$msg = __('Емейл має невірний формат');
				break;
			default:
				$msg = __('Користувача додано');
				break;
		}
		Aurus::getInstance()->addContent( Adminarea::getInstance()->adminInfo($msg) );
	}
} else {
	$groups = Users::getInstance()->getUserGroups();
	$gSelect = '<select name="group">';
	$gSelect .= '<option value="">'.__('Виберіть групу').'</option>';
	foreach ($groups as $id => $gData){
		$gSelect .= '<option value="'.$id.'">'.$gData['groupname'].'</option>';
	}
	$gSelect .= '</select>';

	Aurus::getInstance()->addContent( Aurus::getInstance()->form_start().
	Html::table(
	Html::tr(
	Html::td(__('Ім\'я')).
	Html::td('<input name="login"/>')
	).
	Html::tr(
	Html::td(__('Пароль')).
	Html::td('<input name="pass"/>')
	).
	Html::tr(
	Html::td(__('E-mail')).
	Html::td('<input name="email"/>')
	).
	Html::tr(
	Html::td(__('Група')).
	Html::td($gSelect)
	).
	Html::tr(
	Html::td('<center><input type="submit" value="'.__('Надіслати').'"/></center>','','left','50%','top',2)
	)
	)
	.'</form>' );
}